package com.ternnetwork.core.configuration.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ternnetwork.commons.model.http.BaseResponse;
import com.ternnetwork.commons.utils.JsonUtils;
import com.ternnetwork.core.configuration.dto.SeqQueryDto;
import com.ternnetwork.core.configuration.entity.Seq;
import com.ternnetwork.core.configuration.service.SeqService;



@Controller
@RequestMapping("/configuration/sequence/*")
public class SeqController {
	
	 @Autowired
	 private SeqService seqService;
	
	
	 @RequestMapping("/getOne")
     public @ResponseBody BaseResponse getOne(Long id) {
     	 return seqService.getOne(id);
     }
	
	 /**
	  * hasAnyAuthority('AUTH_SEQ_ADD')
	  * 表示只有AUTH_SEQ_ADD权限的人才能调用
	  * AUTH_SEQ_ADD在 系统设置/访问控制/功能管理 中的“权限代码”中设置
	  * @param requestJson
	  * @return
	  * @throws Exception
	  */
	 @PreAuthorize("hasAnyAuthority('AUTH_SEQ_ADD')")
	 @RequestMapping("/add")
     public @ResponseBody BaseResponse add(String requestJson) throws Exception{
   		BaseResponse baseResponse = new BaseResponse();
		Seq t = JsonUtils.jsonToObjectThrowsException(requestJson, Seq.class);
		baseResponse = seqService.add(t);
		return baseResponse;
     }
	 
	 @PreAuthorize("hasAnyAuthority('AUTH_SEQ_DELETE')")
	 @RequestMapping("/deleteById")
     public @ResponseBody BaseResponse deleteById(Long id) {
    	 return seqService.deleteById(id);
     }
	 
	 @PreAuthorize("hasAnyAuthority('AUTH_SEQ_UPDATE')")
	 @RequestMapping("/update")
     public @ResponseBody BaseResponse update(String requestJson) throws Exception{
		BaseResponse baseResponse = new BaseResponse();
		Seq t = JsonUtils.jsonToObjectThrowsException(requestJson, Seq.class);
		baseResponse = seqService.update(t);
		return baseResponse;
     }
	
	 
	 @PreAuthorize("hasAnyAuthority('AUTH_SEQ_QUERY')")
	 @RequestMapping("/findByPage")
     public @ResponseBody BaseResponse findByPage(@PageableDefault Pageable pageable,SeqQueryDto dto) {
      	 return seqService.findByPage(pageable, dto);
     }
    
	 @RequestMapping("/findAll")
     public @ResponseBody BaseResponse findAll(SeqQueryDto dto) {
    	 return seqService.findAll(dto);
     }
	
	

}
